home *** CD-ROM | disk | FTP | other *** search
- // Acronymity
- // © 2000 by Karl Kornel (kornel.1@osu.edu)
- // Made during MacHack 2000
- // Changes & Redistribution allowed is credit given
-
- /* Our includes */
- #include <iostream.h> // The streams
-
- /* Our special include */
- #include "settings.h" // The user-definable settings
-
- /* The prototypes for the support functions */
- bool confirmQuit(const char *);
- bool confirmAdd(const char *);
- void printHelp(void);
- void clearChar(char *,const int);
- void cleanAcronym(char *);
- bool isLetter(const char);
- char makeItLower(const char);
- int getLetterCode(const char);
-
-
- /* Our functions */
- bool confirmQuit(const char *acronym) {
- if ( (acronym[0] == 'q') && (acronym[1] == 'u') && (acronym[2] == 'i') && (acronym[3] == 't')
- && (acronym[4] == '\0') )
- return true;
- else
- return false;
- }
-
- bool confirmAdd(const char *acronym) {
- if ( (acronym[0] == 'a') && (acronym[1] == 'd') && (acronym[2] == 'd') && (acronym[3] == '\0') )
- return true;
- else
- return false;
- }
-
- void printHelp(void) {
- for (int temp=1;temp < 30;temp++)
- cout << "\n";
- cout << endl;
-
- cout << "Words can be up to " << wordLength << " characters long.\n"
- << "To add a word, open the appropriate text file.\n"
- << "The first letter of the word you want to add\n"
- << " determines the text file that will hold the new word.\n"
- << "For example, you would place the word\"Apple\" in the file\n"
- << " named \"a.txt\", keeping each word on its own line\n" << endl
- << "After adding the word, update the \"index.dat\" file\n"
- << "Each line in the file has a letter, a comma, and a number.\n"
- << "The letter is the name of the text file without the extension.\n"
- << "The number is the number of words in each text file.\n"
- << "Good luck! This program will now quit.\n" << endl;
- }
-
- void clearChar(char *theString, const int length) {
- for (int temp=0;temp <= length-1;temp++)
- theString[temp] = '\0';
- theString[length] = '\0';
- }
-
- void cleanAcronym(char *theAcronym) {
- char newAcronym[acronymLength]; // Make space for the clean version
- clearChar(newAcronym,acronymLength); // Initialize it
-
- int newAcronymLoc = 0; // Current "cursor" position
-
- for (int charNum=0;charNum <= acronymLength - 1;charNum++) { // Do this for each character
- if (isLetter(theAcronym[charNum])) { // If it's actually a letter
- newAcronym[newAcronymLoc] = makeItLower(theAcronym[charNum]); // Copy in the lowercase char.
- newAcronymLoc++; // Advance the cursor by one
- }
- }
-
- for (int charNum=0;charNum <= acronymLength - 1;charNum++) // Do this for each character
- theAcronym[charNum] = newAcronym[charNum]; // Transfer the character
-
- }
-
- bool isLetter(const char theChar) {
- bool reallyLetter = false; // Are we really a letter?
- char lowerLetters[27] = "abcdefghijklmnopqrstuvwxyz"; // The lower-case letters
- char upperLetters[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // The upper-case letters
-
- for (int letter=0;letter <= 25;letter++)
- if (lowerLetters[letter] == theChar)
- reallyLetter = true;
- else if (upperLetters[letter] == theChar)
- reallyLetter = true;
-
- return reallyLetter;
- }
-
- char makeItLower(const char theChar) {
- char retValue; // The value to return
-
- if (theChar == 'A')
- retValue = 'a';
- else if (theChar == 'B')
- retValue = 'b';
- else if (theChar == 'C')
- retValue = 'c';
- else if (theChar == 'D')
- retValue = 'd';
- else if (theChar == 'E')
- retValue = 'e';
- else if (theChar == 'F')
- retValue = 'f';
- else if (theChar == 'G')
- retValue = 'g';
- else if (theChar == 'H')
- retValue = 'h';
- else if (theChar == 'I')
- retValue = 'i';
- else if (theChar == 'J')
- retValue = 'j';
- else if (theChar == 'K')
- retValue = 'k';
- else if (theChar == 'L')
- retValue = 'l';
- else if (theChar == 'M')
- retValue = 'm';
- else if (theChar == 'N')
- retValue = 'n';
- else if (theChar == 'O')
- retValue = 'o';
- else if (theChar == 'P')
- retValue = 'p';
- else if (theChar == 'Q')
- retValue = 'q';
- else if (theChar == 'R')
- retValue = 'r';
- else if (theChar == 'S')
- retValue = 's';
- else if (theChar == 'T')
- retValue = 't';
- else if (theChar == 'U')
- retValue = 'u';
- else if (theChar == 'V')
- retValue = 'v';
- else if (theChar == 'W')
- retValue = 'w';
- else if (theChar == 'X')
- retValue = 'x';
- else if (theChar == 'Y')
- retValue = 'y';
- else if (theChar == 'Z')
- retValue = 'z';
- else
- retValue = theChar;
-
- return retValue;
- }
-
- int getLetterCode(const char theLetter) {
- int theNumber; // The number corresponding to the letter
-
- switch (theLetter) {
- case 'a':
- theNumber = 1;
- break;
- case 'b':
- theNumber = 2;
- break;
- case 'c':
- theNumber = 3;
- break;
- case 'd':
- theNumber = 4;
- break;
- case 'e':
- theNumber = 5;
- break;
- case 'f':
- theNumber = 6;
- break;
- case 'g':
- theNumber = 7;
- break;
- case 'h':
- theNumber = 8;
- break;
- case 'i':
- theNumber = 9;
- break;
- case 'j':
- theNumber = 10;
- break;
- case 'k':
- theNumber = 11;
- break;
- case 'l':
- theNumber = 12;
- break;
- case 'm':
- theNumber = 13;
- break;
- case 'n':
- theNumber = 14;
- break;
- case 'o':
- theNumber = 15;
- break;
- case 'p':
- theNumber = 16;
- break;
- case 'q':
- theNumber = 17;
- break;
- case 'r':
- theNumber = 18;
- break;
- case 's':
- theNumber = 19;
- break;
- case 't':
- theNumber = 20;
- break;
- case 'u':
- theNumber = 21;
- break;
- case 'v':
- theNumber = 22;
- break;
- case 'w':
- theNumber = 23;
- break;
- case 'x':
- theNumber = 24;
- break;
- case 'y':
- theNumber = 25;
- break;
- case 'z':
- theNumber = 26;
- break;
- default: // If no letter exits (shouldn't happen)
- theNumber = 1+ (rand() % 26); // Return a random number to 26
- }
-
- return theNumber - 1; // Return the number, correcting for an array number
- }